﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace QA_System
{
    public class NN_EcllipsisResolve
    {
        static private XMLNounConnection nounconn = new XMLNounConnection();

        static private XMLVerbConnection verbconn = new XMLVerbConnection();

        static    private bool iresolve;

            public NN_EcllipsisResolve()
            {
                iresolve = false;
            }

        static    public bool Iresolve
            {
                get { return iresolve; }
            }

        static    public sentence_tagger ResolveB(SentenceStruct ssPresen,SentenceStruct ssSen)
            {
                try
                {
                    iresolve = false;
                    sentence_tagger senresult = null;
                    WordStruct noun =  null;
                    string strPos = ssPresen.StrSentencePos;
                    int[] preallNounposition = ssPresen.GetNounsPosition();
                    int[] curallNounposition = ssSen.GetNounsPosition();
                    if (preallNounposition.Length > 0)
                    {
                        if (curallNounposition.Length > 0)
                        {
                            if (curallNounposition.Length == 2)
                            {
                                noun = ssSen[curallNounposition[1]];
                            }
                            else if (curallNounposition.Length == 1) noun = ssSen[curallNounposition[0]];
                            if (noun.Pos.Equals("Np")) preallNounposition = ssPresen.GetNpPosition();
                            int j = 0;
                            for (j = 0; j < preallNounposition.Length; j++)
                            {
                                #region nn_eclipsis reslove
                                bool ok = noun.Word.Equals(ssPresen[preallNounposition[j]].Word);
                                if (ok)
                                {
 
                                }
                                else
                                {
                                    ok = nounconn.IsBothAttribute(ssPresen[preallNounposition[j]], noun);
                                    if (ok)
                                    {
                                        senresult = new sentence_tagger(ssPresen.SentenceLength);
                                        int ii = 0;

                                        for (ii = 0; ii < ssPresen.SentenceLength; ii++)
                                        {

                                            senresult[ii].Word_pos = ssPresen[ii].Pos;
                                            if (ii == preallNounposition[j]) senresult[ii].Word_text = noun.Word;
                                            else
                                            {
                                                senresult[ii].Word_text = ssPresen[ii].Word;
                                            }
                                        }

                                        iresolve = true;
                                        break;

                                    }
                                    else
                                    {
                                        ok = nounconn.IsSameType(ssPresen[preallNounposition[j]], noun);
                                        if (ok)
                                        {
                                            senresult = new sentence_tagger(ssPresen.SentenceLength);
                                            int ii = 0;
                                            for (ii = 0; ii < ssPresen.SentenceLength; ii++)
                                            {

                                                senresult[ii].Word_pos = ssPresen[ii].Pos;
                                                if (ii == preallNounposition[j]) senresult[ii].Word_text = noun.Word;
                                                else
                                                {
                                                    senresult[ii].Word_text = ssPresen[ii].Word;
                                                }
                                            }
                                            if (ssPresen[ssPresen.SentenceLength - 1].Word.Equals(".") && (ssSen[ssSen.SentenceLength - 1].Word.Equals("?")))
                                            {
                                                if (ssPresen[preallNounposition[j] - 1].Pos.Equals("M")) senresult[preallNounposition[j] - 1].Word_text = "mấy";
                                                senresult[senresult.Sentence_length - 1].Word_text = "?";
                                            }
                                            iresolve = true;
                                            break;
                                        }
                                        else
                                        {
                                            #region B part of A
                                            ok = nounconn.IsBpartofA(ssPresen[preallNounposition[j]], noun);
                                            if (ok)
                                            {
                                                senresult = new sentence_tagger(ssPresen.SentenceLength + 2);
                                                int ii = 0;
                                                for (ii = 0; ii < ssPresen.SentenceLength + 2; ii++)
                                                {
                                                    if (ii < preallNounposition[j])
                                                    {
                                                        senresult[ii].Word_pos = ssPresen[ii].Pos;
                                                        senresult[ii].Word_text = ssPresen[ii].Word;
                                                    }
                                                    else
                                                    {
                                                        if (ii == preallNounposition[j])
                                                        {
                                                            senresult[ii].Word_pos = noun.Pos;
                                                            senresult[ii].Word_text = noun.Word;
                                                        }
                                                        if (ii == preallNounposition[j] + 1)
                                                        {
                                                            senresult[ii].Word_pos = "C";
                                                            senresult[ii].Word_text = "của";
                                                        }
                                                        if (ii > preallNounposition[j] + 1)
                                                        {
                                                            senresult[ii].Word_pos = ssPresen[ii - 2].Pos;
                                                            senresult[ii].Word_text = ssPresen[ii - 2].Word;
                                                        }
                                                    }
                                                }
                                                iresolve = true;
                                                break;
                                            }
                                            else
                                            {
                                                ok = nounconn.IsBaAttributeOfA(ssPresen[preallNounposition[j]], noun);
                                                if (ok)
                                                {
                                                    senresult = new sentence_tagger(preallNounposition[j] + 2);
                                                    int ii = 0;
                                                    for (ii = 0; ii < senresult.Sentence_length - 1; ii++)
                                                    {

                                                        if (ii == preallNounposition[j] + 1)
                                                        {
                                                            senresult[ii].Word_text = noun.Word;
                                                            senresult[ii].Word_pos = noun.Pos;
                                                        }
                                                        else
                                                        {
                                                            senresult[ii].Word_text = ssPresen[ii].Word;
                                                            senresult[ii].Word_pos = ssPresen[ii].Pos;
                                                        }
                                                    }
                                                    senresult[ii + 1].Word_pos = ssSen[ssSen.SentenceLength].Pos;
                                                    senresult[ii + 1].Word_text = ssSen[ssSen.SentenceLength].Word;

                                                }
                                            }
                                            #endregion
                                        }
                                    }
                                }
#endregion
                            }
                        }

                    }
                    return senresult;
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }

        static public sentence_tagger Resolve(SentenceStruct ssPresen, SentenceStruct ssSen)
        {
            try
            {
                iresolve = false;
                sentence_tagger senresult = null;
                int typeResolve = 0;
                switch (ssPresen[ssPresen.SentenceLength - 1].Pos)
                {
                    case ".": if (ssSen[ssSen.SentenceLength - 1].Pos.Equals(".")) typeResolve = 1;
                        else typeResolve = 2;
                        break;
                    case "?": if (ssSen[ssSen.SentenceLength - 1].Pos.Equals(".")) typeResolve = 3;
                        else typeResolve = 4;
                        break;

                    default: typeResolve = 0; break;
                }
                if (typeResolve ==0) throw new Exception(" Please , you want to ask or answer ?");
                else
                {
                    #region AskWord
                    int[] askwordposition = ssPresen.GetAskWorkPosition(); 
                    if ((askwordposition.Length > 0) && (typeResolve == 3))
                    {

                        switch (ssPresen[askwordposition[0]].Word.ToLower())
                        {
                                #region ai
                            case "ai":
                                int count = 0;

                                for (int index = 0; index < ssSen.SentenceLength; index++)
                                {
                                    if (ssSen[index].WordSubMean.Contains("People")) count++;
                                }
                                if (count > 0)
                                {
                                    senresult = new sentence_tagger(ssPresen.MeanwordLengh() + count-1);
                                    int ssPreindex = 0;
                                    sentence_tagger human = new sentence_tagger(count);
                                    int k = 0;
                                    for (int index = 0; index < ssSen.SentenceLength; index++)
                                    {
                                        if (ssSen[index].WordSubMean.Contains("People"))
                                        {
                                            human[k].Word_pos = ssSen[index].Pos;
                                            human[k].Word_text = ssSen[index].Word;
                                            k++;
                                        }
                                    }
                                    k = 0;
                                    for (int index = 0; index < senresult.Sentence_length; index++)
                                    {
                                        if (ssPresen[ssPreindex].Pos.Equals("Z") && (ssPresen[ssPreindex].Word.ToLower().Equals("ai")))
                                        {
                                            senresult[index].Word_pos = human[k].Word_pos;
                                            senresult[index].Word_text = human[k].Word_text;
                                            k++;
                                            if (k == count) ssPreindex++;
                                        }
                                        else
                                        {
                                            if (!ssPresen[ssPreindex].Pos.Equals("-"))
                                            {
                                                if (ssPresen[ssPreindex].Word.ToLower().Equals("bạn"))
                                                {
                                                    senresult[index].Word_text = "tôi";
                                                }
                                                else
                                                senresult[index].Word_text = ssPresen[ssPreindex].Word;
                                                senresult[index].Word_pos = ssPresen[ssPreindex].Pos;
                                                ssPreindex++;
                                            }
                                            else ssPreindex++;

                                        }
                                    }
                                    senresult[senresult.Sentence_length - 1].Word_text = ".";
                                    senresult[senresult.Sentence_length - 1].Word_pos = ".";
                                    iresolve = true;
                                }
                                
                                break;
                                #endregion
                            #region bao nhieu
                            case "bao nhiêu":
                                count = 0;
                                string strCount="";
                                for (int index = 0; index < ssSen.SentenceLength; index++)
                                {
                                    if(ssSen[index].Pos.Equals("M")) 
                                    { 
                                        count++;
                                        strCount = ssSen[index].Word;
                                    }
                                }
                                if (count == 1)
                                {
                                    senresult = new sentence_tagger(ssPresen.MeanwordLengh());                                    
                                   
                                    for (int index = 0; index < senresult.Sentence_length; index++)
                                    {
                                        if (!ssPresen[index].Pos.Equals("-"))
                                        {
                                            if (ssPresen[index].Word.ToLower().Equals("bao nhiêu"))
                                            {
                                                senresult[index].Word_text = strCount;
                                                senresult[index].Word_pos = "M";
                                            }
                                            else
                                            {
                                                if (ssPresen[index].Word.ToLower().Equals("bạn"))
                                                {
                                                    senresult[index].Word_text = "tôi";
                                                    senresult[index].Word_pos = "N";
                                                }
                                                else
                                                {
                                                    senresult[index].Word_text = ssPresen[index].Word;

                                                    senresult[index].Word_pos = ssPresen[index].Pos;
                                                }
                                            }
                                        }
                                    }
                                    senresult[senresult.Sentence_length - 1].Word_text = ".";
                                    senresult[senresult.Sentence_length - 1].Word_pos = ".";
                                    iresolve = true;
                               
                                }
                                break;
                            #endregion
                            #region dau
                            case "đâu":
                                int[] nounpositon = ssSen.GetNounsPosition();
                                int placeIndex = 0;
                                for (int index = 0; index < ssSen.SentenceLength; index++)
                                {
                                    if (nounconn.GetWordType(ssSen[index], "").Contains("Place") || (nounconn.GetWordType(ssSen[index], "").Contains("BuildingConstruction"))) placeIndex++;
                                }
                                if (placeIndex > 0)
                                {
                                    senresult = new sentence_tagger(ssPresen.MeanwordLengh() - 1 + placeIndex);
                                    sentence_tagger place = new sentence_tagger(placeIndex);
                                    int k = 0;
                                    for (int index = 0; index < ssSen.SentenceLength; index++)
                                    {
                                        if (nounconn.GetWordType(ssSen[index], "").Contains("Place") || (nounconn.GetWordType(ssSen[index], "").Contains("BuildingConstruction")))
                                        {
                                            /*
                                            place[k].Word_pos = ssSen[nounpositon[index]].Pos;
                                            place[k].Word_text = ssSen[nounpositon[index]].Word;
                                            
                                             * */
                                            place[k].Word_pos = ssSen[index].Pos;
                                            place[k].Word_text = ssSen[index].Word;
                                             k++;
                                        }
                                    }
                                    k = 0;
                                    int ssPreindex = 0;
                                    for (int index = 0; index < senresult.Sentence_length; index++)
                                    {
                                        if (ssPresen[ssPreindex].Pos.Equals("Z") && (ssPresen[ssPreindex].Word.ToLower().Equals("đâu")))
                                        {
                                            senresult[index].Word_pos = place[k].Word_pos;
                                            senresult[index].Word_text = place[k].Word_text;
                                            k++;
                                            if (k == placeIndex) ssPreindex++;
                                        }
                                        else
                                        {
                                            if (!ssPresen[ssPreindex].Pos.Equals("-"))
                                            {
                                                if(ssPresen[ssPreindex].Word.ToLower().Equals("bạn"))
                                                {
                                                    senresult[index].Word_text = "tôi";
                                                }
                                                else senresult[index].Word_text = ssPresen[ssPreindex].Word;
                                                senresult[index].Word_pos = ssPresen[ssPreindex].Pos;
                                                ssPreindex++;
                                            }
                                            else ssPreindex++;

                                        }
                                    }
                                    senresult[senresult.Sentence_length - 1].Word_text = ".";
                                    senresult[senresult.Sentence_length - 1].Word_pos = ".";
                                    iresolve = true;
                                }
                                break;
                            #endregion
                            #region nao
                            case "nào":
                                nounpositon = ssSen.GetNpPosition();
                                if (nounpositon.Length > 0)
                                {
                                    senresult = new sentence_tagger(ssPresen.MeanwordLengh());

                                    for (int index = 0; index < senresult.Sentence_length; index++)
                                    {
                                        if (!ssPresen[index].Pos.Equals("-"))
                                        {
                                            if (ssPresen[index].Word.ToLower().Equals("nào"))
                                            {
                                                senresult[index].Word_text = ssSen[nounpositon[0]].Word;
                                                senresult[index].Word_pos = ssSen[nounpositon[0]].Pos;
                                            }
                                            else
                                            {
                                                if (ssPresen[index].Word.ToLower().Equals("bạn"))
                                                {
                                                    senresult[index].Word_text = "tôi";
                                                }
                                                else
                                                {
                                                    senresult[index].Word_text = ssPresen[index].Word;
                                                    senresult[index].Word_pos = ssPresen[index].Pos;
                                                }
                                            }
                                        }
                                    }
                                   

                                    senresult[senresult.Sentence_length - 1].Word_text = ".";
                                    senresult[senresult.Sentence_length - 1].Word_pos = ".";
                                    iresolve = true;
                               
                                }
                                else  
                                {
                                    //TH: hỏi khi nào, lúc nào, năm nào
                                    if (ssPresen[askwordposition[0] - 1].Word.ToLower() == "khi" || ssPresen[askwordposition[0] - 1].Word.ToLower() == "năm"
                                        || ssPresen[askwordposition[0]].Word.ToLower() == "lúc")
                                    {
                                        senresult = new sentence_tagger(ssPresen.MeanwordLengh() + ssSen.CountTime() -1);

                                        for (int index = 0; index < senresult.Sentence_length; index++)
                                        {
                                            
                                                if (ssPresen[index].Word.ToLower().Equals("nào"))
                                                {
                                                    for (int i = 0; i < ssSen.SentenceLength; i++)
                                                    {
                                                        if (ssSen[i].Pos.Equals("M") || ssSen[i].Pos.Equals("Nu"))
                                                        {
                                                            senresult[index].Word_text = ssSen[i].Word;
                                                            senresult[index].Word_pos = ssSen[i].Pos;
                                                            index++;
                                                        }
                                                    }
                                                }
                                                else
                                                {


                                                    if (ssPresen[index].Word.ToLower() == "khi")
                                                    {
                                                        senresult[index].Word_text = "lúc";
                                                    }
                                                    else
                                                        senresult[index].Word_text = ssPresen[index].Word;
                                                    senresult[index].Word_pos = ssPresen[index].Pos;
                                                    
                                                }
                                            }
                                        


                                        senresult[senresult.Sentence_length - 1].Word_text = ".";
                                        senresult[senresult.Sentence_length - 1].Word_pos = ".";
                                        iresolve = true;
                                    }
                                    iresolve = true;
                                    break;

                                }

                                break;
                            #endregion
                            case "làm gì":
                                int[] allVerbposition = ssSen.GetAllVerbPosition();
                                int[] allHuhanPosition = ssPresen.GetHumanNounsPosition();
                                        if ((allVerbposition.Length >= 1) && ssSen.GetNpPosition(0, allVerbposition[0]) == -1)
                                        {
                                            senresult = new sentence_tagger(askwordposition[0]+ssSen.SentenceLength);
                                            ssSen[allVerbposition[0]].Word = ssSen[allVerbposition[0]].Word.ToLower();
                                            string subjectType = verbconn.GetTypeofSubject(ssSen[allVerbposition[0]], "");
                                            int i=0;
                                            if (subjectType.Contains("People"))
                                            {
                                                
                                                for (i = 0; i < askwordposition[0]; i++)
                                                {


                                                    //bool ok = NPanaphoraCondition.IVerbAgree(ssPresen[allVerbposition[0]], ssSen[allHuhanPosition[i]], false);
                                                    //if (ok)
                                                    //{
                                                    senresult[i].Word_pos = ssPresen[i].Pos;
                                                    if (ssPresen[i].Word.ToLower() == "bạn" || ssPresen[i].Word.ToLower() == "anh")
                                                        senresult[i].Word_text = "tôi";
                                                    else
                                                        senresult[i].Word_text = ssPresen[i].Word;

                                                    

                                                    //}


                                                }
                                                iresolve = true;
                                            }
                                            int j = i;
                                            int k = 0;
                                            for (k=allVerbposition[0];  k < ssSen.SentenceLength- 1; k++)
                                            {
                                                
                                                senresult[j].Word_pos = ssSen[k].Pos;
                                                senresult[j].Word_text = ssSen[k].Word;
                                                j++;
                                            }
                                            senresult[senresult.Sentence_length - 1].Word_text = ".";
                                            senresult[senresult.Sentence_length - 1].Word_pos = ".";
                                        }
                                break;
                        }
                    }
                    #endregion
                    //Ham cu
                    int[] allNounPosition = ssPresen.GetNounsPosition();
                    //int[] allNounPosition = ssPresen.GetHumanNounsPositionForNNElipsis();
                    if (allNounPosition.Length > 0)
                    {
                        

                        #region resolve NNresolve
                        if (!iresolve)
                        {
                        int[] ssSenNounPosition = ssSen.GetNounsPosition();
                        if (ssSenNounPosition.Length >=0)
                        {
                            int senLength = ssPresen.MeanwordLengh();
                            if (ssPresen[0].Word.ToLower().Equals("có")) senLength++;
                            switch (typeResolve)
                            {
                                case 3:
                                    int[] allNoun = ssPresen.GetNounsPosition();
                                    if (allNoun.Length > 0)
                                    {
                                        WordStruct word = null;
                                        for (int j = 0; j < ssSen.SentenceLength; j++)
                                        {
                                            if (!ssSen[j].Pos.Equals("-"))
                                            {
                                                word = ssSen[j];
                                                break;
                                            }
                                        }
                                        senresult = new sentence_tagger(ssPresen.MeanwordLengh());
                                        int Pindex = 0;
                                        for (int index = 0; index < senresult.Sentence_length; index++)
                                        {
                                           if (nounconn.IsSameType(ssPresen[Pindex], word))
                                           {
                                                    senresult[index].Word_pos = ssPresen[Pindex].Pos;
                                                    senresult[index].Word_text = word.Word;
                                                    Pindex++;
                                                    iresolve = true;
                                           }
                                           else
                                           {
                                                    if (!ssPresen[Pindex].Pos.Equals("-"))
                                                    {
                                                        senresult[index].Word_pos = ssPresen[Pindex].Pos;
                                                        senresult[index].Word_text = ssPresen[Pindex].Word;
                                                        Pindex++;
                                                    }
                                                    else Pindex++;
                                           }
                                           if (senresult[index].Word_text.ToLower().Equals("bạn")) senresult[index].Word_text = "tôi";
                                        } 
                                      
                                    
                                        senresult[senresult.Sentence_length - 1].Word_text = ".";
                                        senresult[senresult.Sentence_length - 1].Word_pos = ".";
                                    }
                                    if (!iresolve)
                                    {
                                        //vi ko phan tich cu phap nen ko tim dc chu ngu cua cau trc
                                        //-> tinh luoc chu ngu chua giai quyet dc.
                                        //chi gia quyet dc Th don gian nhu: To Ngoc Van di dau? Di hoc
                                        //se tim Np o cau trc va thay the vao. Con TH tim P la chu ngu o cau trc thi chua dc
                                        int[] allVerbposition = ssSen.GetAllVerbPosition();
                                        //Ham cu
                                        int[] allHuhanPosition = ssPresen.GetHumanNounsPosition();
                                        //int[] allHuhanPosition = ssPresen.GetHumanNounsPositionForNNElipsis();
                                        if ((allVerbposition.Length >= 1) && ssSen.GetNpPosition(0, allVerbposition[0]) == -1)
                                        {
                                            senresult = new sentence_tagger(ssSen.SentenceLength+1);
                                            for (int i = 0; i < allHuhanPosition.Count(); i++)
                                            {
                                                
                                                    
                                                    bool ok = NPanaphoraCondition.IVerbAgree(ssPresen[allVerbposition[0]], ssSen[allHuhanPosition[i]], false);
                                                    if (ok)
                                                    {
                                                        senresult[0].Word_pos = ssPresen[allHuhanPosition[i]].Pos;
                                                        senresult[0].Word_text = ssPresen[allHuhanPosition[i]].Word;
                                                        iresolve = true;

                                                    }
                                                    break;
                                                
                                            }
                                            int j = 0;
                                            for (int i = 1;  i < senresult.Sentence_length - 1; i++)
                                            {
                                                
                                                senresult[i].Word_pos = ssSen[j].Pos;
                                                senresult[i].Word_text = ssSen[j].Word;
                                                j++;
                                            }
                                            senresult[senresult.Sentence_length - 1].Word_text = ".";
                                            senresult[senresult.Sentence_length - 1].Word_pos = ".";
                                        }
                                    }
                                    break;
                                case 4:
                                    senresult = new sentence_tagger(ssPresen.SentenceLength);
                                    int[] noun = ssSen.GetNounsPosition();
                                    if (noun.Length > 0)
                                    {
                                        for (int index = 0; index < senresult.Sentence_length; index++)
                                        {
                                            for (int nounindex = 0; nounindex < ssSen.SentenceLength; nounindex++)
                                            {
                                                if (nounconn.IsBsameCatagoryA(ssPresen[index], ssSen[nounindex]))
                                                {
                                                    iresolve = true;
                                                    senresult[index].Word_pos = ssSen[nounindex].Pos;
                                                    senresult[index].Word_text = ssSen[nounindex].Word;
                                                    break;
                                                }
                                            }
                                        }
                                        for (int index = 0; index < senresult.Sentence_length; index++)
                                        {
                                            if (string.IsNullOrEmpty(senresult[index].Word_pos))
                                            {
                                                senresult[index].Word_pos = ssPresen[index].Pos;
                                                senresult[index].Word_text = ssPresen[index].Word;
                                            }
                                        }

                                    }
                                    break;
                            }
                        }
                        }
                        #endregion

                        #region resolve N_Att
                        if (!iresolve)
                        {
                            int[] ssSenNounPosition = ssSen.GetNounsPosition();
                            if (ssSenNounPosition.Length > 0)
                            {
                                int senLength = ssPresen.MeanwordLengh();
                                if (ssPresen[0].Word.ToLower().Equals("có")) senLength++;
                                switch (typeResolve)
                                {
                                    case 3:
                                        int[] allNoun = ssPresen.GetNounsPosition();
                                        if (allNoun.Length > 0)
                                        {
                                            WordStruct word = null;
                                            for (int j = 0; j < ssSen.SentenceLength; j++)
                                            {
                                                if (!ssSen[j].Pos.Equals("-"))
                                                {
                                                    word = ssSen[j];
                                                    break;
                                                }
                                            }
                                            senresult = new sentence_tagger(ssPresen.MeanwordLengh());
                                            int Pindex = 0;
                                            for (int index = 0; index < senresult.Sentence_length; index++)
                                            {
                                                if (nounconn.IsBothAttribute(ssPresen[Pindex], word))
                                                {
                                                    senresult[index].Word_pos = word.Pos;
                                                    senresult[index].Word_text = word.Word;
                                                    Pindex++;
                                                    iresolve = true;
                                                }
                                                else
                                                {
                                                    if (nounconn.IsBaAttributeOfA(ssPresen[Pindex], word))
                                                    {
                                                        senresult[index].Word_pos = ssPresen[Pindex].Pos;
                                                        senresult[index].Word_text = ssPresen[index].Word + " " + word.Word;
                                                        Pindex++;
                                                        iresolve = true;
                                                    }
                                                    else
                                                    {
                                                        if (!ssPresen[Pindex].Pos.Equals("-"))
                                                        {
                                                            senresult[index].Word_pos = ssPresen[Pindex].Pos;                                                            
                                                            senresult[index].Word_text = ssPresen[Pindex].Word;
                                                            Pindex++;
                                                        }
                                                        else Pindex++;
                                                    }
                                                }
                                                if (senresult[index].Word_text.ToLower().Equals("bạn")) senresult[index].Word_text = "tôi";
                                            }
                                            senresult[senresult.Sentence_length - 1].Word_text = ".";
                                            senresult[senresult.Sentence_length - 1].Word_pos = ".";
                                        }
                                        break;
                                    case 4:
                                        allNoun = ssPresen.GetNounsPosition();
                                        if (allNoun.Length > 0)
                                        {
                                            WordStruct word = null;
                                            for (int j = 0; j < ssSen.SentenceLength; j++)
                                            {
                                                if (!ssSen[j].Pos.Equals("-")&& ssSen[j].Pos.Equals("N"))
                                                {
                                                    word = ssSen[j];
                                                    break;
                                                }
                                            }

                                            senresult = new sentence_tagger(ssPresen.SentenceLength);
                                            for (int index = 0; index < ssPresen.SentenceLength; index++)
                                            {
                                                if (nounconn.IsBothAttribute(ssPresen[index], word))
                                                {
                                                    senresult[index].Word_pos = word.Pos;
                                                    senresult[index].Word_text = word.Word;
                                                    iresolve = true;
                                                }
                                                else
                                                {
                                                    /*
                                                    if (nounconn.IsBaAttributeOfA(ssPresen[index], word))
                                                    {
                                                        iresolve = true;
                                                        senresult[index].Word_pos = ssPresen[index].Pos;
                                                        senresult[index].Word_text = word.Word + " của " + ssPresen[index].Word;
                                                        break;
                                                        //senresult[index].Word_text = ssPresen[index].Word + " " + word.Word;
                                                    }
                                                     */
                                                    //else
                                                    {
                                                        senresult[index].Word_pos = ssPresen[index].Pos;
                                                        senresult[index].Word_text = ssPresen[index].Word;
                                                    }

                                                }
                                            }

                                            
                                            
                                            if (!iresolve)
                                            {
                                                int chiso = 0;
                                                senresult = new sentence_tagger(3);
                                                if (ssSen.StrSentencePos.Contains("- R N") || (ssSen.StrSentencePos.Contains("- C N")))
                                                {
                                                    senresult = new sentence_tagger(5);
                                                    senresult[0].Word_pos = "-";
                                                    senresult[0].Word_text = "Thế";
                                                    if (ssSen.IsContain("C"))
                                                        senresult[1].Word_pos = "C";
                                                    else if(ssSen.IsContain("R"))
                                                        senresult[1].Word_pos="R";
                                                    senresult[1].Word_text = "còn";
                                                    chiso = 2;
                                                }
                                                for (int index = 0; index < ssPresen.SentenceLength; index++)
                                                {



                                                    if (nounconn.IsBaAttributeOfA(ssPresen[index], word))
                                                    {
                                                        iresolve = true;
                                                        senresult[chiso+1].Word_pos = ssPresen[index].Pos;
                                                        senresult[chiso+1].Word_text = word.Word + " của " + ssPresen[index].Word;
                                                        break;
                                                        //senresult[index].Word_text = ssPresen[index].Word + " " + word.Word;


                                                    }
                                                }
                                                senresult[senresult.Sentence_length-1].Word_text = "?";
                                                senresult[senresult.Sentence_length-1].Word_pos = "?";
                                            }
                                            
                                        }

                                        break;
                                }
                            }
                        }
                        #endregion
                       
                    }
                    else iresolve = true;
                }
                
                return senresult;
            }
            catch(Exception ex)
            {
                throw ex;
            }
        }
    }
    public class VP_EcllipsisResolve
    {
        static private XMLNounConnection nounconn = new XMLNounConnection();

        static private XMLVerbConnection verbconn = new XMLVerbConnection();

            static private bool iresolve = false;

            public VP_EcllipsisResolve()
            {
                iresolve = false;
            }

            static public bool Iresolve
            {
                get { return iresolve; }
            }
           static    public sentence_tagger Resolve(SentenceStruct ssPresen, SentenceStruct ssSen)
            {
                try
                {
                    iresolve = false;
                    sentence_tagger resultSen = null;
                    int firstVerb = ssSen.GetVerbPosition(0, ssSen.SentenceLength - 1);
                    if (ssSen[firstVerb + 1].Pos.Equals("V")) firstVerb++;
                    if (firstVerb != -1)
                    {
                        int refVerb = ssPresen.GetVerbPosition(0, ssPresen.SentenceLength - 1);
                        if (ssPresen[refVerb + 1].Pos.Equals("V")) refVerb++;
                        if (refVerb != -1)
                        {
                            if (verbconn.IsBsameCatagoryA(ssPresen[refVerb], ssSen[firstVerb]))
                            {
                                int strLength = firstVerb + ssPresen.SentenceLength - refVerb;
                                resultSen = new sentence_tagger(strLength);
                                for (int index = 0; index <= firstVerb; index++)
                                {
                                    resultSen[index].Word_pos = ssSen[index].Pos;
                                    resultSen[index].Word_text = ssSen[index].Word;
                                }
                                for (int index = firstVerb + 1; index < strLength - 1; index++)
                                {
                                    resultSen[index].Word_pos = ssPresen[refVerb+index - firstVerb].Pos;
                                    resultSen[index].Word_text = ssPresen[refVerb + index - firstVerb].Word;
                                }
                                resultSen[strLength - 1].Word_text = ssSen[ssSen.SentenceLength - 1].Word;
                                resultSen[strLength - 1].Word_pos = ssSen[ssSen.SentenceLength - 1].Pos;
                                iresolve = true;
                            }
                            //Vinh them
                            if (ssSen[firstVerb].Word.Equals("muốn") || ssSen[firstVerb].Word.Equals("thích"))
                            {
                                int strLength = firstVerb + ssPresen.SentenceLength - refVerb + 1;
                                resultSen = new sentence_tagger(strLength);
                                for (int index = 0; index <= firstVerb; index++)
                                {
                                    resultSen[index].Word_pos = ssSen[index].Pos;
                                    resultSen[index].Word_text = ssSen[index].Word;
                                }
                                for (int index = firstVerb + 1; index < strLength - 1; index++)
                                {
                                    resultSen[index].Word_pos = ssPresen[refVerb + index - firstVerb -1].Pos;
                                    resultSen[index].Word_text = ssPresen[refVerb + index - firstVerb -1].Word;
                                }
                                resultSen[strLength -1].Word_text = ssSen[ssSen.SentenceLength -1].Word;
                                resultSen[strLength -1].Word_pos = ssSen[ssSen.SentenceLength -1].Pos;
                                iresolve = true;
                            }
                            //ended
                        }
                    }
                    return resultSen;
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
    }
}
